import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../../service/service_method.dart';
import 'package:dio/dio.dart';
import 'dart:convert';

class BlocPage extends StatefulWidget {
  BlocPage({Key key}) : super(key: key);

  @override
  _BlocPageState createState() => _BlocPageState();
}

class _BlocPageState extends State<BlocPage> {
  List blocList = [];
  @override
  void initState() {
    super.initState();
    getBlogPage().then((value) {
      setState(() {
        this.blocList = value;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: SingleChildScrollView(
        child: Container(
          width: ScreenUtil().setWidth(750),
          height: ScreenUtil().setHeight(1100),
          padding: EdgeInsets.fromLTRB(20, 0, 20, 0),
          child: ListView.builder(
            itemCount: this.blocList.length,
            itemBuilder: (context, index) {
              return InkWell(
                child: Container(
                  height: ScreenUtil().setHeight(195),
                  width: ScreenUtil().setWidth(690),
                  padding: EdgeInsets.fromLTRB(0, 15, 0, 15),
                  child: Row(
                    children: <Widget>[
                      Container(
                        width: ScreenUtil().setWidth(490),
                        height: ScreenUtil().setHeight(125),
                        child: Row(
                          children: <Widget>[
                            Text(
                              "${this.blocList[index]['name']}",
                              style: TextStyle(
                                fontSize: 19,
                              ),
                            ),
                            SizedBox(height: 5),
                            Text(
                              "${this.blocList[index]['blocdocs']}",
                              style: TextStyle(
                                fontSize: 13,
                                color: Color.fromRGBO(128, 128, 128, 1),
                              ),
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                            ),
                            SizedBox(height: 10),
                            Text(
                              "${this.blocList[index]['time']}",
                              style: TextStyle(
                                fontSize: 15,
                                color: Color.fromRGBO(179, 179, 179, 1),
                              ),
                            ),
                          ],
                        ),
                      ),
                      Container(
                        width: ScreenUtil().setWidth(200),
                        height: ScreenUtil().setHeight(125),
                        child: Image.network(
                          "${this.blocList[index]['img']}",
                          fit: BoxFit.cover,
                        ),
                      ),
                    ],
                  ),
                ),
                onTap: () {
                  Navigator.pushNamed(context, '/blocdocs',
                      arguments: {"id": "${this.blocList[index]['id']}"});
                },
              );
            },
          ),
        ),
      ),
    );
  }
}
